package kr.hkit.PowerJava.chapter10;

import java.util.Arrays;
import java.util.Random;

public class LottoGenerater2 {
	private boolean[] lotto = new boolean[45];
	private Random rnd;
	private static final int SIZE = 6;

	public LottoGenerater2() {
		lotto = new boolean[45];
		rnd = new Random();

	}

	public void initLotto(){
		for(int i=-0;i<lotto.length; i++){
			lotto[i] = false;
		}
	}
	
	public void getLottoNum() {
		int num = -1;
		for (int i = 0; i < SIZE; i++) {
			num = rnd.nextInt(45);
			if (lotto[num]) { // 중복된 값이 존재
				i--;
			} else {
				lotto[num] = true;
			}
		}
	}

	public void prnLottoNum() {
		for (int i = 0; i < lotto.length; i++) {
			if (lotto[i]) {
				System.out.printf("%3d", i + 1);

			}
		}
	}

	@Override
	public String toString() {
		return "LottoGenerater2 [lotto=" + Arrays.toString(lotto) + "]";
	}

	public static void main(String[] args) {
		LottoGenerater2 lotto = new LottoGenerater2();
		lotto.getLottoNum();
		lotto.prnLottoNum();
	}

}
